home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2 Examples.sit
/
Raven 1.2 Examples
/
Quill
/
Source
/
PaneEditor.cpp
< prev
next >
Wrap
Text File
|
1997-08-10
|
9KB
|
381 lines
/*
* File: PaneEditor.cpp
* Summary: A view that knows how to edit a TPane.
* Written by: Jesse Jones
*
* Copyright ゥ 1996 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 10/15/96 JDJ Created
*/
#include "PaneEditor.h"
#include <ZControl.h>
#include <ZStringUtils.h>
#include <ZTextBox.h>
#include <ZUndoableCommand.h>
#include <ZWindow.h>
#include "Document.h"
// ===================================================================================
// class CPaneInfo
// ===================================================================================
//---------------------------------------------------------------
//
// CPaneInfo::CPaneInfo ()
//
//---------------------------------------------------------------
CPaneInfo::CPaneInfo()
{
}
//---------------------------------------------------------------
//
// CPaneInfo::CPaneInfo (SPaneInfo, string)
//
//---------------------------------------------------------------
CPaneInfo::CPaneInfo(const SPaneInfo& paneInfo, const string& name) : SPaneInfo(paneInfo)
{
className = name;
}
#pragma mark -
// ===================================================================================
// class CNewEditPaneCommand
// ===================================================================================
class CNewEditPaneCommand : public TUndoableCommand {
typedef TUndoableCommand Inherited;
//-----------------------------------
// Initialization/Destruction
//
public:
virtual ~CNewEditPaneCommand();
CNewEditPaneCommand(TPane* pane, const CPaneInfo& oldInfo, const CPaneInfo& newInfo);
//-----------------------------------
// New API
//
public:
static void UpdatePane(TPane* pane, const CPaneInfo& newInfo);
//-----------------------------------
// Inherited API
//
public:
virtual string GetText() const;
virtual bool IsValid() const;
protected:
virtual void OnDo();
virtual void OnUndo();
virtual void OnRedo();
//-----------------------------------
// Member data
//
protected:
TSafePtr<TPane> mPane;
CPaneInfo mOldInfo;
CPaneInfo mNewInfo;
};
//---------------------------------------------------------------
//
// CNewEditPaneCommand::~CNewEditPaneCommand
//
//---------------------------------------------------------------
CNewEditPaneCommand::~CNewEditPaneCommand()
{
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::CNewEditPaneCommand
//
//---------------------------------------------------------------
CNewEditPaneCommand::CNewEditPaneCommand(TPane* pane, const CPaneInfo& oldInfo, const CPaneInfo& newInfo) : mPane(pane)
{
ASSERT(pane != nil);
mOldInfo = oldInfo;
mNewInfo = newInfo;
TWindow* window = dynamic_cast<TWindow*>(mPane->GetTopView());
if (window != nil)
mContext = window->GetUndoContext();
else
mContext = nil;
mDelete = mContext == nil;
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::UpdatePane [static]
//
//---------------------------------------------------------------
void CNewEditPaneCommand::UpdatePane(TPane* pane, const CPaneInfo& info)
{
ASSERT(pane != nil);
if (info.visible)
pane->Show();
else
pane->Hide();
pane->SetOpaque(info.opaque);
pane->SetClassName(info.className);
pane->SetName(info.name);
pane->SetRefCon(info.refCon);
TWindow* window = dynamic_cast<TWindow*>(pane->GetTopView());
ASSERT(window != nil);
CDocument* doc = dynamic_cast<CDocument*>(window->GetSuperCommander());
ASSERT(doc != nil);
CCustomClasses* classes = doc->GetCustomPanes();
string baseClass = typeid(*pane).name();
classes->AddClass(info.className, baseClass);
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::GetText
//
//---------------------------------------------------------------
string CNewEditPaneCommand::GetText() const
{
return ""; // should be inside a transaction
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::IsValid
//
//---------------------------------------------------------------
bool CNewEditPaneCommand::IsValid() const
{
return mPane.TargetExists();
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::OnDo
//
//---------------------------------------------------------------
void CNewEditPaneCommand::OnDo()
{
CNewEditPaneCommand::UpdatePane(mPane.Get(), mNewInfo);
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::OnUndo
//
//---------------------------------------------------------------
void CNewEditPaneCommand::OnUndo()
{
CNewEditPaneCommand::UpdatePane(mPane.Get(), mOldInfo);
}
//---------------------------------------------------------------
//
// CNewEditPaneCommand::OnRedo
//
//---------------------------------------------------------------
void CNewEditPaneCommand::OnRedo()
{
CNewEditPaneCommand::UpdatePane(mPane.Get(), mNewInfo);
}
#pragma mark -
// ===================================================================================
// CPaneEditor
// ===================================================================================
static TReanimatorRegister<CPaneEditor> sNewPaneEditorRegistrar;
//---------------------------------------------------------------
//
// CPaneEditor::~CPaneEditor
//
//---------------------------------------------------------------
CPaneEditor::~CPaneEditor()
{
}
//---------------------------------------------------------------
//
// CPaneEditor::CPaneEditor
//
//---------------------------------------------------------------
CPaneEditor::CPaneEditor(TView* superView) : CRootPaneEditor(superView)
{
mPane = nil;
}
//---------------------------------------------------------------
//
// CPaneEditor::SetPane
//
//---------------------------------------------------------------
void CPaneEditor::SetPane(TPane* pane)
{
ASSERT(pane != nil);
ASSERT(mPane == nil);
mPane = pane;
mOldInfo = CPaneInfo(mPane->GetInfo(), mPane->GetClassName());
this->SetEditorInfo(mOldInfo);
}
//---------------------------------------------------------------
//
// CPaneEditor::Create [static]
//
//---------------------------------------------------------------
MReanimatable* CPaneEditor::Create(MReanimatable* parent)
{
return new CPaneEditor(dynamic_cast<TView*>(parent));
}
//---------------------------------------------------------------
//
// CPaneEditor::Apply
//
//---------------------------------------------------------------
void CPaneEditor::Apply()
{
CPaneInfo info = this->GetEditorInfo();
this->SetPaneInfo(info);
}
//---------------------------------------------------------------
//
// CPaneEditor::Commit
//
//---------------------------------------------------------------
void CPaneEditor::Commit(TMultipleUndoableCommand* command)
{
CPaneInfo newInfo = this->GetEditorInfo();
command->AddCommand(new CNewEditPaneCommand(mPane, mOldInfo, newInfo));
}
//---------------------------------------------------------------
//
// CPaneEditor::Revert
//
//---------------------------------------------------------------
void CPaneEditor::Revert()
{
this->SetEditorInfo(mOldInfo);
this->SetPaneInfo(mOldInfo);
}
//---------------------------------------------------------------
//
// CPaneEditor::GetEditorInfo
//
//---------------------------------------------------------------
CPaneInfo CPaneEditor::GetEditorInfo() const
{
CPaneInfo info;
TTextBox* textBox = nil;
TControl* control = nil;
textBox = dynamic_cast<TTextBox*>(this->FindSubPane("Class Name"));
info.className = textBox->GetText();
textBox = dynamic_cast<TTextBox*>(this->FindSubPane("Pane Name"));
info.name = textBox->GetText();
control = dynamic_cast<TControl*>(this->FindSubPane("Visible"));
info.visible = control->GetValue();
control = dynamic_cast<TControl*>(this->FindSubPane("Opaque"));
info.opaque = control->GetValue();
textBox = dynamic_cast<TTextBox*>(this->FindSubPane("RefCon"));
info.refCon = textBox->GetValue();
return info;
}
//---------------------------------------------------------------
//
// CPaneEditor::SetEditorInfo
//
//---------------------------------------------------------------
void CPaneEditor::SetEditorInfo(const CPaneInfo& info)
{
TTextBox* textBox = nil;
TControl* control = nil;
textBox = dynamic_cast<TTextBox*>(this->FindSubPane("Class Name"));
textBox->SetText(info.className);
textBox = dynamic_cast<TTextBox*>(this->FindSubPane("Pane Name"));
textBox->SetText(info.name);
control = dynamic_cast<TControl*>(this->FindSubPane("Visible"));
control->SetValue(info.visible);
control = dynamic_cast<TControl*>(this->FindSubPane("Opaque"));
control->SetValue(info.opaque);
textBox = dynamic_cast<TTextBox*>(this->FindSubPane("RefCon"));
textBox->SetValue(info.refCon);
}
//---------------------------------------------------------------
//
// CPaneEditor::SetPaneInfo
//
//---------------------------------------------------------------
void CPaneEditor::SetPaneInfo(const CPaneInfo& info)
{
CNewEditPaneCommand::UpdatePane(mPane, info);
}